package com.dein.user.service.impl;

import com.dein.user.model.User;
import com.dein.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.dein.user.dao.UserDao;


@Service("userService")
public	class  UserServiceImpl implements UserService {
	
	protected UserDao userDao;
	

	@Autowired
	@Qualifier("userDao")
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}


    @Override
    public Long userLogin(String userName, String userPw) {
        try{
            return  userDao.userLogin(userName,userPw);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public User getUserById(Long userId) {
        try {
            return  userDao.getUserById(userId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean updateUser(User user) {
        try {
            userDao.updateUser(user);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return  true;
    }

    @Override
    public boolean userExist(String userName) {
        try {
            if(userDao.userExist(userName)>0)
                return  true;
            else
                return  false;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean userRegist(User user) {
        try {
            userDao.userRegist(user);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return  true;
    }
}
